<?php
class Admin_IndexController extends Zend_Controller_Action{
    private $_params;
	private $_auth;	
    public function init(){
        $this->_params      = $this->_request->getParams();        
        $this->_auth        = new My_Auth();
        $this->view->auth   = $this->_auth;        
        $this->_auth        = $this->_auth->checkAuthentication();
        $this->view->auth   = $this->_auth;
    }
    public function indexAction(){
        $configPrice= new Zend_Config_Ini(CONFIG_PATH.'/price.ini', APPLICATION_ENV);        
        $price=$configPrice->price->toArray();
        $this->view->price = $price;        
        $configWebsite= new Zend_Config_Ini(CONFIG_PATH.'/website.ini', APPLICATION_ENV);        
        $configWebsite=$configWebsite->website->toArray();
        $this->view->configWeb = $configWebsite;        
    }
    public function priceAction(){
        $formData = $this->getRequest()->getPost();        
        if(is_numeric($formData['price'])){
            $config = new Zend_Config_Ini(CONFIG_PATH.'/price.ini',APPLICATION_ENV,array('skipExtends' => true, 'allowModifications' => true));                
            $config->price->price = $formData['price'];                
            $writer = new Zend_Config_Writer_Ini();
            $writer->setFilename(CONFIG_PATH.'/price.ini');        
            $writer->setConfig($config);        
            $writer->write();
            $this->_helper->redirector('index','index','admin');               
        }else{   
            echo "<script>alert('Phí đăng tin không hợp lệ');</script>";
            $this->_helper->redirector('index','index','admin');                        
        }                                
    }    
    public function pricetopAction(){
        $formData = $this->getRequest()->getPost();        
        if(is_numeric($formData['pricetop'])){
            $config = new Zend_Config_Ini(CONFIG_PATH.'/price.ini',APPLICATION_ENV,array('skipExtends' => true, 'allowModifications' => true));                
            $config->price->refresh->top = $formData['pricetop'];                            
            $writer = new Zend_Config_Writer_Ini();
            $writer->setFilename(CONFIG_PATH.'/price.ini');        
            $writer->setConfig($config);        
            $writer->write();
            $this->_helper->redirector('index','index','admin');               
        }else{   
            echo "<script>alert('Phí không hợp lệ');</script>";
            $this->_helper->redirector('index','index','admin');                        
        }                                
    }	
    public function freedateAction(){
        $formData = $this->getRequest()->getPost();        
        if(is_numeric($formData['freedate'])){
            $config = new Zend_Config_Ini(CONFIG_PATH.'/website.ini',APPLICATION_ENV,array('skipExtends' => true, 'allowModifications' => true));                
            $config->website->freedate = $formData['freedate'];                
            $writer = new Zend_Config_Writer_Ini();
            $writer->setFilename(CONFIG_PATH.'/website.ini');        
            $writer->setConfig($config);        
            $writer->write();
            $this->_helper->redirector('index','index','admin');                
        }else{   
            echo "<script>alert('Số ngày mặc định không phù hợp !!');</script>";
            $this->_helper->redirector('index','index','admin');                        
        }    
    }
}